<?php
/* 
 * Copyright (C) 2010 Emanuele Colonnelli <emanuele.colonnelli@phpstruct.org>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
namespace org\phpstruct\json;

/**
 * Description of JsonException
 *
 * @author Emanuele Colonnelli <emanuele.colonnelli@phpstruct.org>
 */
class JsonException extends \Exception {

	public $type;
	public $code;
	public $message;

	private static $knowncodes = array('1062' => "Dato gi&aacute; esistente.");

	public function __construct(\Exception $e) {

		parent::__construct();

		$r = new \ReflectionObject($e);
		$this->type = $r->getName();
		$this->code = isset($e->errorInfo) ? $e->errorInfo[1] : $e->getCode();
		$this->message = isset(self::$knowncodes[$this->code]) ? self::$knowncodes[$this->code] : $e->getMessage();

		die(\json_encode($this));
	}

}

